home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 51 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  5.8 KB

  1. Path: senator-bedfellow.mit.edu!red-branch!rid
  2. From: rid@red-branch.MIT.EDU (Shawna Grimm)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Listview Problem
  5. Date: 2 Jan 1996 15:28:34 GMT
  6. Organization: Massachvsetts Institvte of Technology
  7. Message-ID: <4cbiv2$sgg@senator-bedfellow.MIT.EDU>
  8. References: <4c8iqo$h16@newsserv.grfn.org>
  9. NNTP-Posting-Host: red-branch.mit.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Jeret Lendman (jlendman@grfn.org) wrote:
  13. : Ok, I want to thank all those who are helping.  This post is to show all 
  14. : the changes that have been made.  Richard Katzman was correct that the 
  15. : minlist was the wrong type to allocate for.  And it has been changed.  
  16. : here is my code again with changes.
  17.  
  18. : I have made many comments in the code to show where the help is being 
  19. : done.  Again, I feel it necessary to say thanx. 
  20.  
  21. : struct TextAttr Topaz80 = {(STRPTR)"topaz.font",8,0,0};
  22. :  
  23. : /*******
  24. :     makelabels is called from the main function, and is the first thing.
  25. :     Then I open libraries, screen, and window.  And just before opening
  26. :     the window, I call makegadgets.  I mention this because, someone
  27. :     mentioned GT_RefreshWindow/Gadgets.  I create the gadget list and
  28. :     attach the list before opening the window.  Refreshing should not be
  29. :     neccessary.  But I could be wrong.
  30. : *******/
  31. :  
  32. : void makegadgets(void)
  33. : {
  34. :   struct Gadget *qgadget;
  35. :   int *vi=NULL;
  36. :  
  37. :   vi = GetVisualInfo(xscreen, TAG_END);
  38. :   if(!vi)
  39. :     printf("Error: Get Visual Info!\n");
  40. :  
  41. :   qgadget = (struct Gadget *)CreateContext(&gadgetlist);
  42. :  
  43. :   newgadget = (struct NewGadget *)AllocVec(sizeof(struct NewGadget), 
  44. : MEMF_CLEAR);
  45. :   newgadget->ng_LeftEdge   = 4;
  46. :   newgadget->ng_TopEdge    = 20;
  47. :   newgadget->ng_Width      = 250;
  48. :   newgadget->ng_Height     = 160;
  49. :   newgadget->ng_GadgetText = NULL;
  50. :   newgadget->ng_TextAttr   = &Topaz80;
  51. :   newgadget->ng_GadgetID   = 1;
  52. :   newgadget->ng_Flags      = 0;
  53. :   newgadget->ng_VisualInfo = vi;
  54. :  
  55. :   qgadget = CreateGadget(LISTVIEW_KIND, qgadget, newgadget, GTLV_Labels, 
  56. : namelist, TAG_END);
  57. : }
  58. :  
  59. :   makegadgets();
  60. :   xwindow = (struct Window *)OpenWindowTags(NULL, WA_Left, 0,
  61. :                                                   WA_Top,  0,
  62. :                                                   WA_Width, 640,
  63. :                                                   WA_Height, 200,
  64. :                                                   WA_DetailPen, 2,
  65. :                                                   WA_BlockPen, 0,
  66. :                                   WA_IDCMP, (LISTVIEWIDCMP) | IDCMP_RAWKEY,
  67. :                                                   WA_Gadgets, gadgetlist,
  68. :                                                   WA_Title, windowtitle,
  69. :                                                   WA_CustomScreen, xscreen,
  70. :                                   WA_Flags, WFLG_SMART_REFRESH | WFLG_ACTIVATE);
  71. :  
  72. : void makelabels(void)
  73. : {
  74. :   size_t q;
  75. :   char x;
  76. :  
  77. :   xtype = 0;
  78. :   xfp = (FILE *)fopen("Xenolink:users/Userfile.xlk","rb+");
  79. :   fseek(xfp, sizeof(struct User), SEEK_SET);
  80. :  
  81. :   namelist = (struct List *)AllocVec(sizeof(struct List), MEMF_CLEAR );
  82. :   if(!namelist)
  83. :   {
  84. :     printf("Error: Allocating Memory for List!\n");
  85. :     exit(0);
  86. :   }
  87. :   else
  88. :   {
  89. :     namelist->lh_Type=0; <- I have not read anywere that suggests what
  90. :                             value goes here.  The book I have called
  91. :                             "Mapping the Amiga" lists the different types
  92. :                             of lists, but nothing for a general user list.
  93. :                             I have reset this back to 0 for an unknown type.
  94. :                             or should it be a 1.
  95. :  
  96. :     NewList((struct List *)namelist);
  97. :   }
  98. :  
  99. :   do
  100. :   {
  101. :     q = fread(&xuser, sizeof(struct User), 1L, xfp);
  102. :     if(q)
  103. :     {
  104. :       char *name;
  105. :  
  106. :       name = (char *)AllocVec(sizeof(xuser.Name), MEMF_CLEAR);
  107. :       if(!name)
  108. :         printf("Error: Allocating Memory for name!\n");
  109. :       namenode = (struct Node *)AllocVec(sizeof(struct Node), MEMF_CLEAR);
  110. :       if(!namenode)
  111. :         printf("Error: Allocating Memory for namenode!\n");
  112. :       namenode->ln_Name = name;
  113. :  
  114. :       for(x=0; xuser.Name[x]; x++)
  115. :         name[x] = xuser.Name[x];
  116. :  
  117. : /****   ^^^^^^^^^^^^^^^^^^^^^^
  118. :       I am still using this method to copy because when I AllocVec space
  119. :       for the name all bytes are MEMF_CLEAR(ed).  When the _for_ statment
  120. :       finishes, there are plenty of NULLs to terminate the string.
  121. :       The sizeof xuser.Name is 25 bytes for those who were wondering.
  122. : ****/  <-  I use the comment marks out of habit.
  123. :  
  124. :  
  125. :       namenode->ln_Type = 100; <- I have not read anything to tell me
  126. :                                   what value is proper.  the value here
  127. :                                   is from the RKM example.
  128. :  
  129. :       AddTail((struct List *)namelist, (struct Node *)namenode);
  130. :     }
  131. :   }while(q);
  132. :  
  133. :   if(xfp)
  134. :     fclose((FILE *)xfp);
  135. : }
  136.  
  137. : *****************************************************************************
  138.  
  139. : Does anyone have an example that could be posted that works.  I can not 
  140. : find any on aminet that includes the source that has a listview.
  141.  
  142. : ******************************************************************************
  143.  
  144. :   Jeret Lendman                                  E-Mail Jlendman@grfn.org
  145. :   Grand Rapids MI.
  146.  
  147.  
  148. :                          Long live the Amiga
  149. :                 Amiga 1200 with GVP's turbo series II
  150. :                             50MHz/+8megs
  151.  
  152. :                      Loving Every Minute Of It!
  153.  
  154. : ******************************************************************************
  155.  
  156. Look for a program called gadtoolsbox, it should be on aminet somewhere. Even
  157. if you don't want to use it all the time, it will still give you some hints on
  158. how to set up things like Listviews etcetc.
  159.  
  160.